package com.mondo.financialwallet.data;

import com.mondo.financialwallet.data.entity.BasisResponseEntity;

import java.net.ConnectException;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class RetrofitCallback<T extends BasisResponseEntity> implements Callback<T> {

    private final OnFailure onFailure;

    private final DataSource.DataCallback<T> mCallback;

    RetrofitCallback(DataSource.DataCallback<T> callback, OnFailure onFailure) {
        this.mCallback = callback;
        this.onFailure = onFailure;
    }

    @Override
    public void onResponse(Call<T> call, Response<T> response) {
        mCallback.onResult(response.body());
    }

    @Override
    public void onFailure(Call<T> call, Throwable t) {
        if (t instanceof ConnectException) {
            //onFailure.onFailure(C.NETWORK_NOT_NETWORK, t.getMessage());
        } else {
            //onFailure.onFailure(C.NETWORK_UNKNOWN_ERROR, t.getMessage());
        }
    }


    public interface OnFailure {
        void onFailure(int code, String message);
    }
}
